package com.api.test;

import org.springframework.test.context.ContextConfiguration;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.api.client.model.ApiRequest;
import com.api.client.model.ApiResponse;
import com.api.model.ApiRequestBuilder;
import com.api.services.DomainUser;
import com.api.test.AbstractApiTest;
import com.api.test.VoidContextLoader;
import com.zyncro.api.IGroupApiService;
import com.zyncro.api.exceptions.ZyncroApiException;

@ContextConfiguration(loader = VoidContextLoader.class)
public class GetGroupsCompatibility extends AbstractApiTest {

	@BeforeClass
	protected void setUp() throws Exception {

		DomainUser mainAdmin = getDomainRepo().getDomainUser("Groups");

		getApi().login(mainAdmin.getAppId(), mainAdmin.getPassword());
	}

	@Test
	public void testGetAllGroups() throws ZyncroApiException {

		ApiRequestBuilder requestBuilder = getApi().getRequest(IGroupApiService.class, "getGroups");
		getApi().signRequest(requestBuilder);

		ApiRequest request = requestBuilder.getRequest();
		Assert.assertTrue(request.getUrl().endsWith("/api/v1/rest/groups"), "Request url");

		ApiResponse response = request.send();

		Assert.assertEquals(response.getCode(), 200, "Response code");
		Assert.assertNotNull(response.getBody(), "Response body");
		Assert.assertNotEquals(response.getBody(), "", "Response body");
	}
}
